var contents = {
  label: [
    ['申请', '发布', '进行中', '已完成'],
    ['Applications', 'Published', 'Ongoing', 'Finished'],
  ], 
  modules: [
    ['设置', '客服'],
    ['Options', 'Contact'],
  ], 
  info: [
    { visitor: '点击登录', module: "常用功能", news: "新的申请", blank: '暂无新的申请', sign: '申请了你的：'  },
    { visitor: 'Sign up', module: "Modules", news: "Infomation", blank: 'No new infomation', sign: '申请了你的：'  }
  ],
  identity:[
    ['去认证','学生','教师'],
    ['go to identify','student','teacher']
  ]
},
tip_register = [
  { tip: '登录后查看噢~', confirm: '前往登录', cancel: '先看看' },
  { tip: 'Sign up to view more', confirm: 'Sign up', cancel: 'Not now' },
];

Page({
  data: {
    newInfo: [],  // 存储“新的信息”内容
    showMask: true,
    visitor: true,
    iconUrl: '/assets/module/',
    name: '',
    identity: '',
    identityStatus:0,
  },

  onShow() {
    wx.onShow(this, 'custom', wx.theme);
    this.setData({
      noAvatar: wx.appData.user.avatar == '' ? true : false,
      avatar: wx.appData.user.avatar,  
      info: contents.info[wx.lang],
      identity:contents.identity[wx.lang]

    })
   // console.log("认证信息：",this.data.identity)
    if (!wx.appData.user.name) return; // 接下来要注册过才发送请求
    wx.post('User.getUserInfo', { idUser: wx.appData.user.iduser}, res => {
   //  console.log("用户信息：",res);
      wx.appData.user.signup = res.data.userInfo.signup;
      wx.appData.user.finish = res.data.userInfo.finish;
      wx.appData.user.publish = res.data.userInfo.publish;
      wx.appData.user.ongoing = res.data.userInfo.ongoing;
      wx.appData.user.identity=res.data.userInfo.identity;
      this.setData({
        identityStatus:res.data.userInfo.identity
      })
     // console.log("认证信息：",this.data.identity[this.data.identityStatus])
      this.setData({
        label: [
          { id: 'L-1', name: contents.label[wx.lang][0], num: wx.appData.user.signup },
          { id: 'L-2', name: contents.label[wx.lang][1], num: wx.appData.user.publish },
          { id: 'L-3', name: contents.label[wx.lang][2], num: wx.appData.user.ongoing },
          { id: 'L-4', name: contents.label[wx.lang][3], num: wx.appData.user.finish },
        ],
      })
      this.setData({ newInfo: res.data.data ? res.data.data : [] });
    })
  },
  
  onHide(url) {
    wx.onHide(this, url);
  },
  
  onReady() {
    this.setData({ theme: wx.theme })
    let list = [];
    if (wx.appData.user.name) this.setData({ visitor: false });
    this.setData({
      info: contents.info[wx.lang],
      modules: [
        { id: 'M-0', name: contents.modules[wx.lang][0], img: "options" },
      ],
      contact: 
        { id: 'C', name: contents.modules[wx.lang][1], img: "contact" },
      label: [
        { id: 'L-1', name: contents.label[wx.lang][0], num: wx.appData.user.signup },
        { id: 'L-2', name: contents.label[wx.lang][1], num: wx.appData.user.publish },
        { id: 'L-3', name: contents.label[wx.lang][2], num: wx.appData.user.ongoing },
        { id: 'L-4', name: contents.label[wx.lang][3], num: wx.appData.user.finish },
      ]
    });
  },

  // “新的申请”跳转
  cardTap(e) {
    wx.showLoading({ title: "" })
    var target = this.data.newInfo;
    for (let j = 0; j < target.length; ++j) {
      if (e.currentTarget.id == target[j].idpractice) {
        target[j].userInfo = wx.appData.user;
        console.log(target[j].gmtend, new Date(target[j].gmtend*1000));
        target[j].endTime = wx.formatTime(new Date(target[j].gmtend * 1000), '/');
        let string = JSON.stringify(target[j]);
        wx.onHide(this, `../release/detail/detail?content=${encodeURIComponent(string)}`);
        wx.hideLoading();
        break;
      }
    }
  },

  tap(e) {
    var series = e.currentTarget.id.split('-')[0],
      index = parseInt(e.currentTarget.id.split('-')[1]);
    if (series == 'L') {  /** L */
      if (!index) {
        if (!this.data.visitor) return;
        else wx.nav('../../../home/register/register');
      } else if (this.data.visitor) {
        wx.modal(null, tip_register[wx.lang].tip,
          tip_register[wx.lang].cancel, tip_register[wx.lang].confirm,
          null, null,  // navigate to registration if not registered.
          () => { wx.nav('../../../home/register/register') }, () => { return; }
        );
      } else {
        var path = [ '',
          '../signup/list/list',
          '../release/list/list',
          '../ongoing/list/list',
          '../finish/list/list',
        ];
        this.onHide(path[index]);
      }
    } else if (series == 'M') {  /** M */
      var path = [
        '../../module/options/options',
      ];

      this.onHide(path[index]);
    } else if (series == 'C') {  /** C */
      

    }
    return;
  },
  //跳转到认证页面（认证为学生or教师）
  identify(e){
    wx.navigateTo({
      url: '/pages/module/index/identify/identify',
    })
  }
})